import React from 'react';
import {Navigate, useLocation} from "react-router-dom";
import {rootRouter} from "@/router/index.jsx";
import {searchRoute} from "@/util/index.js";
import {getToken} from "@/util/token.js";

const AuthRouter = ({children}) => {
    const {pathname} = useLocation();
    const route = searchRoute(pathname, rootRouter);
    // const tokenData = getToken();
    // console.log("tokenData =", tokenData)
    // 1- 有token 访问的是login
    // if (!tokenData && pathname === "/login") return <Navigate to="/home" replace/>;
    //
    // 2- 访问的是不需要权限的页面
    // if (!route.meta?.requiresAuth) return children;
    //
    // // 3- 当前账号有权限返回 Router，正常访问页面
    return children;
};

export default AuthRouter;